package com.bw.gmall.realtime.app.test;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;

public class phonexutile_rjn {
    public static final String PHOENIX_DRIVER = "org.apache.phoenix.jdbc.PhoenixDriver";
    public static final String PHOENIX_SERVER = "jdbc:phoenix:hadoop102,hadoop103,hadoop104:2181";

    // 获取连接
    public static Connection getConnection() throws Exception {
        Class.forName(PHOENIX_DRIVER);
        return DriverManager.getConnection(PHOENIX_SERVER);
    }

    // 动态获取表的字段名
    public static Set<String> getColumns(String schema, String tableName) throws Exception {
        Set<String> columns = new HashSet<>();
        Connection conn = getConnection();

        DatabaseMetaData metaData = conn.getMetaData();
        ResultSet rs = metaData.getColumns(null, schema.toUpperCase(), tableName.toUpperCase(), null);

        while (rs.next()) {
            String columnName = rs.getString("COLUMN_NAME");
            columns.add(columnName);
        }

        rs.close();
        conn.close();
        return columns;
    }

    public static void main(String[] args) throws Exception {

        String schema = "GMALL_REALTIME";
        String tableName = "DIM_SKU_INFO_ZYJ";

        // 调用方法获取列名
        Set<String> columns = phonexutile_rjn.getColumns(schema, tableName);

        // 打印输出
        System.out.println("表 " + schema + "." + tableName + " 的列名:");
        for (String col : columns) {
            System.out.println(col);

        }




    }
}